﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using YJKArch.DictModule;

namespace YJKArch.DimensionModule
{
	public partial class DlgAddEntry : System.Windows.Forms.Form
	{
		public DlgAddEntry(DlgDictForm mForm)
		{
			this.mainForm = mForm;
			this.InitializeComponent();
		}

		private void btnAdd_Click(object sender, EventArgs e)
		{
			if (this.tbxName.Text != "" && this.mainForm.treeView1.SelectedNode != null)
			{
				if (DictOperation.AddStringEntry((XmlNode)this.mainForm.treeView1.SelectedNode.Tag, new StringEntry(this.tbxName.Text, this.rtbIndex.Text, null), this.mainForm.dictFile.FullName))
				{
					TreeNode selectedNode = this.mainForm.treeView1.SelectedNode;
					this.mainForm.lbxEntry.Items.Clear();
					XmlNode node = (XmlNode)selectedNode.Tag;
					this.mainForm.GetChildAttributes(node, this.mainForm.lbxEntry);
					this.mainForm.lbxEntry.Sorted = true;
					MessageBox.Show("添加成功", "盈建科词库");
				}
				else
				{
					MessageBox.Show("添加失败", "盈建科词库");
				}
			}
			base.Close();
		}

		public static DlgAddEntry GetInstance(DlgDictForm main)
		{
			if (DlgAddEntry.dae == null || DlgAddEntry.dae.IsDisposed)
			{
				DlgAddEntry.dae = new DlgAddEntry(main);
				DlgAddEntry.dae.MdiParent = main.ActiveMdiChild;
			}
			return DlgAddEntry.dae;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private static DlgAddEntry dae;

		private DlgDictForm mainForm;
	}
}
